package com.ljf.tijian.service;

import com.ljf.tijian.ApiResponse;
import com.ljf.tijian.mapper.CheckitemMapper;
import com.ljf.tijian.mapper.SetmealMapper;
import com.ljf.tijian.pojo.Checkitem;
import com.ljf.tijian.pojo.Setmeal;
import com.ljf.tijian.pojo.Users;
import com.ljf.tijian.service.Impl.SetmealServiceImpl;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class SetmealService implements SetmealServiceImpl {

    @Autowired
    SetmealMapper setmealMapper;

    @Autowired
    CheckitemMapper checkitemMapper;

    @Override
    public ApiResponse listSetmealBySex(Users user) {
        List<Setmeal> setmealList = setmealMapper.selectByType(user);

        for (Setmeal setmeal : setmealList) {
            List<Checkitem> checkitemList = new ArrayList<>();
            checkitemList = checkitemMapper.listCheckItemBySmId(setmeal);
            setmeal.setCheckitemList(checkitemList);
        }
        return new ApiResponse(200,"SUCCESS",setmealList);
    }

    @Override
    public ApiResponse getSetmealById(Setmeal setmeal) {

        return new ApiResponse(200,"SUCCESS",setmealMapper.selectByPrimaryKey(setmeal.getSmId()));
    }

    @Override
    public Setmeal getSetmeal(Setmeal setmeal) {
        Setmeal setmeal_res = setmealMapper.selectByPrimaryKey(setmeal.getSmId());

        return setmeal_res;
    }
}
